package com.qianfeng.openapi.web.master.controller;

import com.baomidou.mybatisplus.extension.api.R;
import com.qianfeng.openapi.web.master.aop.MyLog;
import com.qianfeng.openapi.web.master.dto.TableData;
import com.qianfeng.openapi.web.master.dto.TableParam;
import com.qianfeng.openapi.web.master.entity.SysMenu;
import com.qianfeng.openapi.web.master.service.SysMenuService;
import com.qianfeng.openapi.web.master.utils.ShiroUtils;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;
import java.util.List;

/**
 * @Description:
 * @Company: 千锋互联
 * @Author: 李丽婷
 * @Date: 2020/11/25
 * @Time: 下午5:02
 */
@RestController
public class SysMenuController {


    @Resource
    private SysMenuService sysMenuService;

    /**
     * 返回用户能访问的菜单
     * @return
     */
    @MyLog(value = "左侧菜单",description = "展示该用户能访问的菜单")
    @RequestMapping("/sys/menu/user")
    public R  menuUser(){
        long uid = ShiroUtils.getCurrentUserId();//当前登录的用户编号怎么获取？？
       return sysMenuService.leftMenuList(uid);
    }

    //入参：limit=10&offset=0&search=aa&sort=menuId&order=desc
    //出参：{total:xx,rows:[{},]}
    @MyLog(value = "菜单列表",description = "分页展示所有的菜单")
    @RequestMapping("/sys/menu/list")
    public TableData menuList(TableParam param){

        return  sysMenuService.findMenuByPage(param);
    }
    @MyLog(value = "菜单树",description = "新增和修改的时候以树形结构展示菜单和目录")
    @RequestMapping("/sys/menu/select")
    public   R  menuTree(){

        return  sysMenuService.menuTree();
    }

    @MyLog(description = "新增菜单、目录、按钮")
    @RequestMapping("/sys/menu/save")
    public   R  save(@RequestBody SysMenu sysMenu){
        return  sysMenuService.save(sysMenu);
    }

    //   /sys/menu/info/1
    @MyLog(description = "根据编号查看菜单")
    @RequestMapping("/sys/menu/info/{menuId}")
    public  R menuInfo(@PathVariable long menuId){

        return  sysMenuService.findMenuById(menuId);
    }
    @MyLog(description = "修改菜单")
    @RequestMapping("/sys/menu/update")
    public  R  update(@RequestBody SysMenu sysMenu){
        return  sysMenuService.updateMenu(sysMenu);
    }

   // @RequiresPermissions("sys:menu:del")
    @MyLog(description = "批量删除菜单")
    @RequestMapping("/sys/menu/del") // [1,2,3,4,5]
    public  R  delete(@RequestBody List<Integer> ids){
        return  sysMenuService.deleteBatch(ids);
    }
}
